<?php

/**
 * Contact filter form base class.
 *
 * @package    tfe
 * @subpackage filter
 * @author     3emeIG
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 24171 2009-11-19 16:37:50Z Kris.Wallsmith $
 */
abstract class BaseContactFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'nom'                                  => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'prenom'                               => new sfWidgetFormFilterInput(),
      'code'                                 => new sfWidgetFormFilterInput(),
      'date_de_naissance'                    => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'rue'                                  => new sfWidgetFormFilterInput(),
      'numero'                               => new sfWidgetFormFilterInput(),
      'code_postal'                          => new sfWidgetFormFilterInput(),
      'localite'                             => new sfWidgetFormFilterInput(),
      'pays'                                 => new sfWidgetFormFilterInput(),
      'envoyer_news_par_mail'                => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'envoyer_news_par_lettre'              => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'origine_info'                         => new sfWidgetFormChoice(array('choices' => array('' => '', 'Presse' => 'Presse', 'Amis' => 'Amis', 'Bouche à oreille' => 'Bouche à oreille', 'Affiches' => 'Affiches', 'Internet' => 'Internet', 'Autre' => 'Autre'))),
      'commentaire'                          => new sfWidgetFormFilterInput(),
      'client'                               => new sfWidgetFormChoice(array('choices' => array('' => '', 'non' => 'non', 'oui' => 'oui'))),
      'staff'                                => new sfWidgetFormChoice(array('choices' => array('' => '', 'non' => 'non', 'oui' => 'oui'))),
      'animateur'                            => new sfWidgetFormChoice(array('choices' => array('' => '', 'non' => 'non', 'oui' => 'oui'))),
      'artiste'                              => new sfWidgetFormChoice(array('choices' => array('' => '', 'non' => 'non', 'oui' => 'oui'))),
      'externe'                              => new sfWidgetFormChoice(array('choices' => array('' => '', 'non' => 'non', 'oui' => 'oui'))),
      'deleted_at'                           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'created_at'                           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'                           => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'newsletters_list'                     => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Newsletter')),
      'groupes_list'                         => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Groupe')),
      'courriers_electroniques_envoyes_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'CourrierElectronique')),
    ));

    $this->setValidators(array(
      'nom'                                  => new sfValidatorPass(array('required' => false)),
      'prenom'                               => new sfValidatorPass(array('required' => false)),
      'code'                                 => new sfValidatorPass(array('required' => false)),
      'date_de_naissance'                    => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'rue'                                  => new sfValidatorPass(array('required' => false)),
      'numero'                               => new sfValidatorPass(array('required' => false)),
      'code_postal'                          => new sfValidatorPass(array('required' => false)),
      'localite'                             => new sfValidatorPass(array('required' => false)),
      'pays'                                 => new sfValidatorPass(array('required' => false)),
      'envoyer_news_par_mail'                => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'envoyer_news_par_lettre'              => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'origine_info'                         => new sfValidatorChoice(array('required' => false, 'choices' => array('Presse' => 'Presse', 'Amis' => 'Amis', 'Bouche à oreille' => 'Bouche à oreille', 'Affiches' => 'Affiches', 'Internet' => 'Internet', 'Autre' => 'Autre'))),
      'commentaire'                          => new sfValidatorPass(array('required' => false)),
      'client'                               => new sfValidatorChoice(array('required' => false, 'choices' => array('non' => 'non', 'oui' => 'oui'))),
      'staff'                                => new sfValidatorChoice(array('required' => false, 'choices' => array('non' => 'non', 'oui' => 'oui'))),
      'animateur'                            => new sfValidatorChoice(array('required' => false, 'choices' => array('non' => 'non', 'oui' => 'oui'))),
      'artiste'                              => new sfValidatorChoice(array('required' => false, 'choices' => array('non' => 'non', 'oui' => 'oui'))),
      'externe'                              => new sfValidatorChoice(array('required' => false, 'choices' => array('non' => 'non', 'oui' => 'oui'))),
      'deleted_at'                           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'created_at'                           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'                           => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'newsletters_list'                     => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Newsletter', 'required' => false)),
      'groupes_list'                         => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Groupe', 'required' => false)),
      'courriers_electroniques_envoyes_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'CourrierElectronique', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('contact_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addNewslettersListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.MembreNewsletter MembreNewsletter')
          ->andWhereIn('MembreNewsletter.id_newsletter', $values);
  }

  public function addGroupesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.MembreGroupe MembreGroupe')
          ->andWhereIn('MembreGroupe.id_groupe', $values);
  }

  public function addCourriersElectroniquesEnvoyesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.ContactDestinataire ContactDestinataire')
          ->andWhereIn('ContactDestinataire.id_courrier_electronique', $values);
  }

  public function getModelName()
  {
    return 'Contact';
  }

  public function getFields()
  {
    return array(
      'id'                                   => 'Number',
      'nom'                                  => 'Text',
      'prenom'                               => 'Text',
      'code'                                 => 'Text',
      'date_de_naissance'                    => 'Date',
      'rue'                                  => 'Text',
      'numero'                               => 'Text',
      'code_postal'                          => 'Text',
      'localite'                             => 'Text',
      'pays'                                 => 'Text',
      'envoyer_news_par_mail'                => 'Boolean',
      'envoyer_news_par_lettre'              => 'Boolean',
      'origine_info'                         => 'Enum',
      'commentaire'                          => 'Text',
      'client'                               => 'Enum',
      'staff'                                => 'Enum',
      'animateur'                            => 'Enum',
      'artiste'                              => 'Enum',
      'externe'                              => 'Enum',
      'deleted_at'                           => 'Date',
      'created_at'                           => 'Date',
      'updated_at'                           => 'Date',
      'newsletters_list'                     => 'ManyKey',
      'groupes_list'                         => 'ManyKey',
      'courriers_electroniques_envoyes_list' => 'ManyKey',
    );
  }
}
